using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Models;
using FiltronASP.Models.DAO.Interfaces;
using FiltronASP.Models.DAO;
using FiltronASP.Helpers.Translations;

namespace FiltronASP.Helpers.AjaxModel
{
    public class implementationsHelpers
    {

        public static string getSingleMonth(string currentMonth, int languageId, string year)
        {
            IPageDAO pageDAO = new PageDAO();
            ILanguageDAO languageDAO = new LanguageDAO();
            string currentLanguage = "english";            
            Language language = languageDAO.FindByPK(languageId);
            if (language != null)
            {
                currentLanguage = language.language_name;
                if (!String.IsNullOrEmpty(currentLanguage))
                {
                    currentLanguage = currentLanguage.ToLower();
                }   //if
            }   //if
            IGalleryImageDAO galleryImageDAO = new GalleryImageDAO();
            IVariableValueDAO variableValueDAO = new VariableValueDAO();
            List<int> currentMonthPages = new List<int>();
            string toResponse = String.Empty;
            IQueryable<Page> currentMonthImplementationsCollection = pageDAO.findNewsByPageAndLanguageIdAndMonth(7, currentMonth, year, true);
            if (currentMonthImplementationsCollection != null)
            {
                foreach (Page singlePageInCurrentMonth in currentMonthImplementationsCollection)
                {
                    DateTime currentTime = DateTime.UtcNow;
                    currentMonthPages.Add(singlePageInCurrentMonth.page_id);
                }
            }

            toResponse += "<!--                                nagłówek-->";
            toResponse += "<div class=\"col-xs-12 no-padding\">";
            toResponse += "  <div class=\"col-sm-12 col-xs-12 no-padding overlay-engine2 \">";
            toResponse += "      <div class=\" col-md-2 col-xs-3 no-padding \">";
            toResponse += "      <p>" + translationHelper.getTranslation("_newsFilterNumber", currentLanguage) + "</p>";
            toResponse += "    </div>";
            toResponse += " <div class=\"col-md-2 col-xs-2 no-padding overlay-engine-boder-r overlay-engine-boder-l\">";
            toResponse += "    <p>" + translationHelper.getTranslation("_newsType", currentLanguage) + "</p>";
            toResponse += " </div>";
            toResponse += "<div class=\" col-md-6 col-xs-4 no-padding overlay-engine-boder-r\">";
            toResponse += " <p>" + translationHelper.getTranslation("_newsMainApplication", currentLanguage) + "<p>";

            toResponse += " </div>";
            toResponse += "<div class=\"col-md-2 col-xs-3 no-padding overlay-engine-boder-r\" style=\"border-right: 1px solid #000;\">";
            toResponse += "<p>" + translationHelper.getTranslation("_downloadPDF", currentLanguage) + "</p>";
            toResponse += "</div>";
            toResponse += "</div>";

            toResponse += "</div>";
            toResponse += "<!--nagłwek-->";


            foreach (int test in currentMonthPages)
            {
                String pdfLink = String.Empty;
                VariableValue filterNumber = variableValueDAO.FindByVariableAndPage("FilterNumber", Convert.ToInt32(test), 7);
                VariableValue filterType = variableValueDAO.FindByVariableAndPage("FilterType", Convert.ToInt32(test), 7);
                VariableValue application = variableValueDAO.FindByVariableAndPage("Application", Convert.ToInt32(test), 7);

                IQueryable<GalleryImage> galleryImages = galleryImageDAO.FindByGalleryNameAndPage("newsPDF", Convert.ToInt32(test));
                if (galleryImages != null)
                {
                    pdfLink = galleryImages.First().gallery_image_link;
                }

                toResponse += "<div class=\"col-xs-12 no-padding filter-border-l-r\">";
                toResponse += "<div class=\"col-sm-12 col-xs-12 no-padding filter-nfo\" style=\"  display: flex; float: left;   height: auto!important;\">";
                toResponse += "  <div class=\"col-md-2 col-xs-3 no-padding  filter-border-r\">";
                toResponse += "<p class=\"filter-nfo-bold\" style=\"margin-top: 15px; margin-bottom: 15px;\">";
                toResponse += filterNumber.variable_value;
                toResponse += "</p>";
                toResponse += "</div>";
                toResponse += "<div class=\"col-md-2 col-xs-2 no-padding  filter-border-r \">";
                toResponse += "<p  class=\"filter-nfo-light \" style=\"  margin-top: 15px; margin-bottom: 15px;\">";
                toResponse += implementationsHelpers.translateFilterType(filterType.variable_value, currentLanguage);
                toResponse += "</p>";
                toResponse += "</div>";
                toResponse += "<div class=\" col-md-6 col-xs-4 no-padding  filter-border-r \">";
                toResponse += "<p  class=\"filter-nfo-light\" ";
                toResponse += "style=\" margin-top: 15px; margin-bottom: 15px; padding-left: 10px;padding-right: 10px;\">";
                toResponse += application.variable_value;
                toResponse += " </p>";

                toResponse += "</div>";
                toResponse += "<div class=\"col-md-2 col-xs-3 no-padding  \">";
                toResponse += "<p  class=\"filter-nfo-light\" style=\"text-align: left;margin-left: 15px; margin-top: 20px; margin-bottom: 15px;width: auto;\" >";
                toResponse += "<a href=\"" + pdfLink + "\" style=\"color: #000; text-decoration: underline;\">";
                toResponse += "<img style=\"  margin-top: -7px; margin-right: 5px;\" src=\"" + VirtualPathUtility.ToAbsolute("~/Content/img/pdf.png") + "\" alt=\"pdf\">";
                toResponse += translationHelper.getTranslation("_downloadPDF", currentLanguage);
                toResponse += "</a></p>";
                toResponse += "</div>";
                toResponse += "</div>";
                toResponse += "</div>";

            }

            return toResponse;
        }

        private static string translateFilterType(string englishType, string languageId)
        {
            string newEnglishType = englishType.ToLower();

            switch (newEnglishType)
            {
                case "air filter":
                    return translationHelper.getTranslation("_airFilter", languageId);

                case "oil filter":
                    return translationHelper.getTranslation("_oilFilter", languageId);

                case "fuel filter":
                    return translationHelper.getTranslation("_fuelFilter", languageId);

                case "cabin filter":
                    return translationHelper.getTranslation("_cabinFilter", languageId);

                default:
                    return englishType;

            }
        }

    }
}
